// common.cpp
#include <graphics.h>
#include <stdlib.h>
#include <conio.h>
#include <iostream.h>
#include "common.hpp"

void comon::Initialize()
{
    GraphDriver=DETECT;
    initgraph(&GraphDriver,&GraphMode,"..\\bgi");
    ErrorCode=graphresult();
    if (ErrorCode!=0)
    {
			closegraph();
			cout<<"Graphics System Error: "
	    <<grapherrormsg(ErrorCode);
			exit(1);
    }
}

void comon::Pauses()
{
    static char msg[]="Press any key to continue...";
    StatusLine(msg);
    if (kbhit()!=0) getch();
    getch();
    cleardevice();
}

void comon::StatusLine(char *msg)
{
    int Height;
    MaxX=380;
    MaxY=470;
    MaxColors=getmaxcolor()+1;
    setviewport(0,0,MaxX,MaxY,1);
    setcolor(MaxColors-1);
    settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
    settextjustify(CENTER_TEXT,TOP_TEXT);
    setlinestyle(SOLID_LINE,1,NORM_WIDTH);
    setfillstyle(EMPTY_FILL,0);
    Height=textheight(msg);
    bar(50,MaxY-(Height+4),MaxX,MaxY);
    rectangle(50,MaxY-(Height+4),MaxX,MaxY);
    outtextxy(MaxX/2,MaxY-(Height+2),msg);
    setviewport(51,Height+5,MaxX-1,MaxY-(Height+5),1);
}

void comon::Pause()
{
	if (kbhit())
	    getch();
	getch();
}

void comon::program_end()
{
	closegraph();
}

void comon::program_cont()
{
	closegraph();
	Initialize();
}
